package com.cn.integration.business.usercenter.service.impl;

import com.cn.common.model.AuthUser;
import com.cn.common.utils.exception.ServiceException;
import com.cn.common.utils.jwt.JwtUtil;
import com.cn.integration.business.usercenter.dto.LoginDto;
import com.cn.integration.business.usercenter.service.UserService;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Override
    public String login(LoginDto dto) {
        //查询用户
        String phone = dto.getPhone();
        AuthUser authUser = getUserByPhone(phone);
        //校验密码
        if(!dto.getPassWord().equals("123")){
            throw new ServiceException("密码错误");
        }
        return JwtUtil.createToken(authUser);
    }

    private AuthUser getUserByPhone(String phone){
        AuthUser authUser = new AuthUser();
        authUser.setUserId(212147616487572480L);
        authUser.setUserName("张三");
        authUser.setUserType(1);
        authUser.setPhone(phone);
        authUser.setPassWord("123");
        return authUser;
    }
}
